/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sais.eswn.card.cardlabel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

/**
 *
 * @author Romulus
 */
public class SpellLabel extends CardLabel {

    private int region = -1;
    private SpellLabel self = this;

    public SpellLabel(ICardLabelCallback parent, int controller, String cardno, int direction, boolean isWatcher) {
        super(parent, cardno, controller, isWatcher);
        addMouseListener(new SpellMouseListener(this));
    }

    public void setRegion(int region) {
        this.region = region;
    }

    public int getRegion() {
        return region;
    }

    public void setPopupMenu() {
        if (cardno == null) {
            return;
        }
        if (mMenu != null) {
            remove(mMenu);
        }
        mMenu = new JPopupMenu();
        JMenuItem title = new JMenuItem(getInfo().name);
        mMenu.add(title);
        mMenu.addSeparator();
        /*
        if (controller == Player.OPP || isWatcher) {
            add(mMenu);
            return;
        }

        switch (region) {
            case MainFrame.INPLAY_STANDBY:
                for (int k = 0; k < 5; ++k) {
                    int targetregion = MainFrame.REGION_GRAVE;
                    JMenuItem item = null;
                    switch (k) {
                        case 0:
                            item = new JMenuItem(Tools.loc[176]);
                            targetregion = MainFrame.REGION_TOACTIVATED;
                            break;
                        case 1:
                            mMenu.addSeparator();
                            item = new JMenuItem(Tools.loc[172]);
                            targetregion = MainFrame.REGION_GRAVE;
                            break;
                        case 2:
                            item = new JMenuItem(Tools.loc[173]);
                            targetregion = MainFrame.REGION_HAND;
                            break;
                        case 3:
                            item = new JMenuItem(Tools.loc[174]);
                            targetregion = MainFrame.REGION_LIBRARY;
                            break;
                        case 4:
                            item = new JMenuItem(Tools.loc[188]);
                            targetregion = MainFrame.REGION_NOCOSTUSE;
                            break;
                    }
                    item.addActionListener(new SpellCommandListener(targetregion));
                    item.setFont(new java.awt.Font(java.util.ResourceBundle.getBundle("MainFrame").getString("popmenu.font"), 0, 14));
                    mMenu.add(item);
                }
                break;
                
            case MainFrame.INPLAY_ACTIVATED:
                for (int k = 0; k < 5; ++k) {
                    JMenuItem item = null;
                    int targetregion = MainFrame.REGION_GRAVE;
                    switch (k) {
                        case 0:
                            item = new JMenuItem(Tools.loc[178]);
                            targetregion = MainFrame.REGION_TOBATTLE;
                            break;
                        case 1:
                            mMenu.addSeparator();
                            item = new JMenuItem(Tools.loc[177]);
                            targetregion = MainFrame.REGION_TOSTANDBY;
                            break;
                        case 2:
                            item = new JMenuItem(Tools.loc[172]);
                            targetregion = MainFrame.REGION_GRAVE;
                            break;
                        case 3:
                            item = new JMenuItem(Tools.loc[173]);
                            targetregion = MainFrame.REGION_HAND;
                            break;
                        case 4:
                            item = new JMenuItem(Tools.loc[174]);
                            targetregion = MainFrame.REGION_LIBRARY;
                            break;
                    }
                    item.addActionListener(new SpellCommandListener(targetregion));
                    item.setFont(new java.awt.Font(java.util.ResourceBundle.getBundle("MainFrame").getString("popmenu.font"), 0, 14));
                    mMenu.add(item);
                }
                break;

            case MainFrame.INPLAY_BATTLING:
                break;

            default:
                assert false;
        }

        add(mMenu);
         * */
    }

    class SpellCommandListener implements ActionListener {

        int targetregion;

        SpellCommandListener(int targetregion) {
            this.targetregion = targetregion;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            //parent.SpellMove(self, targetregion);
        }
    }

    class SpellMouseListener extends MouseAdapter {

        SpellLabel target;

        SpellMouseListener(SpellLabel target) {
            this.target = target;
        }

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            try {
                if (parent == null) {
                    return;
                }
                parent.showCard(cardno);

                if (evt.getButton() == MouseEvent.BUTTON1 && !evt.isControlDown()) {
                    //parent.AttachDo(controller, region, target);
                } else {
                    mMenu.show(evt.getComponent(), evt.getX(), evt.getY() - MENUSHIFT);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

